package com.qfedu.food.dao;

import com.qfedu.food.pojo.TCollect;
import com.qfedu.food.pojo.TFood;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

public interface CollectDao {
    @Select("select id from t_user where username=#{username}")
    Integer getUidByUsername(String username);

    @Select("select id from t_food where fname=#{fname}")
    Integer getFidByFname(String fname);

    @Insert("insert into t_collect(fid,uid,statu) values(#{fid},#{uid},1)")
    Integer addCollect(int uid , int fid);

    @Select("select * from t_collect where uid = #{uid} and fid = #{fid}")
    TCollect getCollect(int uid , int fid);

    @Update("UPDATE t_collect SET statu=0 where uid = #{uid}")
    Integer delCollectByUidAndFid(int uid);

    @Update("UPDATE t_collect SET statu=1 where uid = #{uid}")
    Integer updateCollectByUidAndFid(int uid);

    @Select("select fid from t_collect where uid = #{uid} and statu = 1")
    List<Integer> getFidByUid(int uid);

    @Select("<script>select t_food.fname,t_food.fimg,t_food.fdesc,t_food.fdetail from t_food where t_food.id in\n" +
            "        <foreach collection=\"fids\" open=\"(\" close=\")\" item=\"id\" separator=\",\">#{id}\n" +
            "        </foreach></script>")
    List<TFood> getFoodByid(List<Integer> fids);
}
